package cn.yza.基础.对象的创建;

import java.lang.reflect.Constructor;

/**
 * @author Honglixi
 * @create 2021-11-03 15:54
 */
public class Test {
    public static void main(String[] args) throws Exception{
        //使用new
        Person person = new Person();
        System.out.println(person);
        //使用反射
        Person.class.getDeclaredConstructor().setAccessible(true);
        Person person1 = Person.class.newInstance();
        System.out.println(person1);
        //使用反射2
        Constructor<Person> constructor = Person.class.getConstructor();
        Person person2 = constructor.newInstance();
        System.out.println(person2);
        //
        Class<?> person3 = Class.forName("cn.yza.基础.对象的创建.Person");
        Person o = (Person) person3.newInstance();
        System.out.println(o);
        //使用clone

    }
}
